package ru.ipo.dces.plugins.admin.components;

import ru.ipo.dces.clientservercommunication.ContestDescription;
import ru.ipo.dces.plugins.admin.beans.ContestsListBean;
import javax.swing.*;

public class ContestList extends JList {

    public ContestList() {
        setCellRenderer(new IconListRenderer());
    }

    public void setDescription(ContestDescription[] desc) {

        ListModel listModel;
        if (desc.length == 0)
            listModel = new AbstractListModel() {
                public int getSize() {
                    return 1;
                }

                public Object getElementAt(int index) {
                    return "Нет доступных соревнований";
                }
            };
        else {
            ContestsListBean[] contestBeans = new ContestsListBean[desc.length];
            for (int i = 0; i < desc.length; i++)
                contestBeans[i] = new ContestsListBean(desc[i]);
            listModel = new DefaultComboBoxModel(contestBeans);
        }
        setModel(listModel);
    }
}
